# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

import os
import shutil

class Recipe(recipe.Recipe):
    """
    Sets up build based on the tinyalsa library.
    """
    name = 'tinyalsa'
    version = '0.1'
    licenses = [License.Apachev2]
    btype = BuildType.MAKEFILE
    remotes = {'origin': 'https://github.com/tinyalsa/tinyalsa'}
    commit = '1.1.1'

    files_devel = [ 'include/tinyalsa/asoundlib.h' ]

    files_libs = [ 'libtinyalsa' ]

    def prepare(self):
        if self.config.target_platform != Platform.LINUX and self.config.target_platform != Platform.ANDROID:
            raise InvalidRecipeError(self, "Invalid platform")

    async def install(self):
        include_path = os.path.join(self.config.prefix, 'include', 'tinyalsa')
        library_path = os.path.join(self.config.prefix, 'lib')

        tinyalsa_header = os.path.join(self.build_dir, 'include', 'tinyalsa', 'asoundlib.h')
        tinyalsa_lib = os.path.join(self.build_dir, 'src', 'libtinyalsa.a')

        if not os.path.exists(include_path):
            os.makedirs(include_path)

        shutil.copy(tinyalsa_header, include_path)
        shutil.copy(tinyalsa_lib, library_path)
